#include "UDPClient.h"
#include "Foundation.h"
#include "ErrorCode.h"

#ifdef __LINUX__
#include <netinet/in.h>
#endif // __LINUX__

int CUDPClient::Connect(const std::string strHost, const int nPort)
{
	int nTemp = CFoundation::IPv4ToLong(strHost);
	if (-1 == nTemp)
	{
		return NETDEBUG_IP_ERR;
	}
	unsigned long lIp = (unsigned long)nTemp;

	if (0 >= nPort || 65535 <= nPort)
	{
		return NETDEBUG_PORT_ERR;
	}

	m_nSocket_fd = SOCKET_CREATE(AF_INET, SOCK_DGRAM, 0);
	if (SOCKET_CHECK(m_nSocket_fd))
	{//Create socket error
		return NETDEBUG_SOCKET_ERR;
	}

	m_addrHost.sin_family = AF_INET;
	m_addrHost.sin_port = htons(nPort);
	m_addrHost.sin_addr.s_addr = lIp;

	return 0;
}